package uni.androidgame.gameobjects;

import android.graphics.Canvas;
import android.graphics.Paint;
import uni.androidgame.*;

import java.lang.*;

public class Monster extends uni.androidgame.Character
{
    private Paint _color;

    public Monster(Tile tile,String name,int str, int hp, int color)
    {
        super(tile,name,str,hp);
        _color = new Paint();
        _color.setColor(color);
    }

    public GameAction createNextAction(Player player)
    {
       if(_isDead)
       {
           return null;
       }
        float smallestDistance = Float.MAX_VALUE;
        Tile nextTile = currentTile;
        float currentDistance;

        for(Tile tile : currentTile.getNeighbours())
        {
            currentDistance =tile.distanceTo(player.getCurrentTile());
            if(currentDistance<smallestDistance)
            {
                smallestDistance = currentDistance;
                nextTile = tile;
            }
        }
        if(nextTile != currentTile)
        {
            if(nextTile.getCharacter() == player)
            {
                return new GameAction(this, GameAction.Type.Attack,nextTile,null);
            }
            else
            {
                return new GameAction(this, GameAction.Type.Move,nextTile,null);
            }
        }

        return new GameAction(this, GameAction.Type.Wait,null,null);
    }

    public void draw(Canvas canvas)
    {
        if(!_isDead)
        {
            canvas.drawCircle(_position.x+ DungeonMap.TileSize/2,_position.y+DungeonMap.TileSize/2,DungeonMap.TileSize/3, _color);
        }
    }

    @Override
    public void kill()
    {
        super.kill();
    }
}
